package com.adkun.markdown.controller;

import com.adkun.markdown.common.ResponseModel;
import com.adkun.markdown.markdown.MarkdownParser;
import com.adkun.markdown.markdown.MdTools;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 前端接口
 */
@RestController
@CrossOrigin(origins = {"${adkun.web.path}"}, allowedHeaders = "*", allowCredentials = "true")
public class MdController {

    @PostMapping("/parse")
    public ResponseModel mdParseHtml(String md) {
        List<String> list = MdTools.splitStr(md);
        MarkdownParser parser = new MarkdownParser();
        String parsed = parser.parseMd(list);
        return new ResponseModel(parsed);
    }
}
